/**
 * 
 */
package linkedlist;

/**
 * @author Michael
 *
 */
public class Node<E extends Comparable<? super E>> implements Comparable<Node<E>> {
	public Node<E> prev = null;
	public Node<E> next = null;
	public E value = null;
	
	/*
	 * Default constructor
	 */
	public Node() { }
	
	/**
	 * 
	 */
	public Node(E value) {
		this.value = value;
	}
	
	public Node(E value, Node<E> next) {
		this.value = value;
		this.next = next;
	}

	public int length() {
		int length = 1;
		while (this.next != null) {
			++length;
		}
		return length;
	}
	
	public String toString() {
		return "Node (value: " + value.toString() + ", next: "
				+ (next == null ? "null" : next.value) + ")";
	}
		

	@Override
	public int compareTo(Node<E> o) {
		if (this.value == o.value)
			return 0;
		
		return this.value.compareTo(o.value);
	}

}
